package com.lagou.edu.course.controller;

import com.alibaba.fastjson.JSON;
import com.lagou.edu.course.api.dto.CoursePlayHistoryDTO;
import com.lagou.edu.course.remote.CoursePlayHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 课程播放历史controller
 *
 * @author lm
 * @since 2021/11/2 10:05
 */
@Slf4j
@RestController
@RequestMapping("/course/coursePlayHistory")
public class CoursePlayHistoryController {
    @Autowired
    private CoursePlayHistoryService coursePlayHistoryService;

    /**
     * 获取课程播放节点
     *
     * @param lessonId 课时ID
     * @return
     */
    @GetMapping(value = "/getByLessonId",consumes = "application/json")
    public CoursePlayHistoryDTO getByLessonId(@RequestParam("lessonId") Integer lessonId, @RequestParam("userId")Integer userId){
        return  coursePlayHistoryService.getCoursePlayHistoryByLessonId(lessonId,userId);
    }

    /**
     * 保存播放历史
     * @param playHistoryDTO
     * @return
     */
    @PostMapping(value = "/saveCourseHistoryNode",consumes = "application/json")
    void saveCourseHistoryNode(@RequestBody CoursePlayHistoryDTO playHistoryDTO){
        log.info("保存历史节点 playHistoryDTO:{}", JSON.toJSONString(playHistoryDTO));
        coursePlayHistoryService.saveCourseHistoryNode(playHistoryDTO);
    }
}
